package com.wunong.smart.address.domain.operation.impl;

import com.wunong.smart.address.domain.UserAddressDomain;
import com.wunong.smart.address.application.context.UserAddressContext;
import com.wunong.smart.address.domain.operation.AbstractUserAddressOperation;
import com.wunong.smart.address.application.request.DeleteUserAddressRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 删除用户地址
 * 1.设置失效状态
 *
 * @author create by zealot.zt
 */
@Slf4j
@Component
public class DeleteUserAddressOperation extends AbstractUserAddressOperation<DeleteUserAddressRequest> {

    @Override
    protected Object doOperate(UserAddressContext<DeleteUserAddressRequest> context) {
        UserAddressDomain domain = context.getDomain();

        // 设置为无效
        domain.setValid(false);

        userAddressRepository.update(domain);
        log.warn("delete user address success, userId:{}, addressId:{}",
                domain.getUserId(), domain.getId());

        return domain.getId();
    }

    @Override
    public Class<DeleteUserAddressRequest> getRequestClass() {
        return DeleteUserAddressRequest.class;
    }

}
